﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using System.Text;
using Microsoft.AspNetCore.Mvc;
using BCDto.Sim.Admin.StaffOrganizationMappingRecord;
using BCTMSRESTful.Configs;
using BCService.Utils;
using BCService.Sim.Admin.StaffOrganizationMappingRecord;

namespace BCTMSRESTful.Controllers.Management.Sim.Admin.StaffOrganizationMappingRecord
{
    /// <summary>
    /// 员工组织映射记录
    /// </summary>
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]
    public class StaffOrganizationMappingRecordController : ManagementBaseController
    {
        private readonly IStaffOrganizationMappingRecordService staffOrganizationMappingRecordService;

        public StaffOrganizationMappingRecordController(IStaffOrganizationMappingRecordService staffOrganizationMappingRecordService)
        {
            this.staffOrganizationMappingRecordService = staffOrganizationMappingRecordService;
        }

        #region 添加员工组织映射记录
        /// <summary>
        ///  添加员工组织映射记录
        /// </summary>
        /// <param name="requestDto">员工组织映射记录信息</param>
        /// <response code="201">添加员工组织映射记录成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加员工组织映射记录")]
        [ProducesResponseType(typeof(StaffOrganizationMappingRecordDto), 201)]
        public IActionResult Post(
            [FromBody]StaffOrganizationMappingRecordRequestDto requestDto)
        {
            var result = this.staffOrganizationMappingRecordService.Add(requestDto);
            return this.Created(string.Format("api/v1/sim/StaffOrganizationMappingRecord/{0}", result.StaffOrganizationMappingRecordId), result);
        }
        #endregion

        #region 修改员工组织映射记录
        /// <summary>
        ///  修改员工组织映射记录
        /// </summary>
        /// <param name="staffOrganizationMappingRecordId">员工组织映射记录Id</param>
        /// <param name="requestDto">员工组织映射记录信息</param>
        /// <response code="200">修改员工组织映射记录成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{staff_organization_mapping_record_id}")]
        [Log("修改员工组织映射记录")]
        [ProducesResponseType(typeof(StaffOrganizationMappingRecordDto), 200)]
        public IActionResult Put([FromRoute(Name = "staff_organization_mapping_record_id")]long staffOrganizationMappingRecordId, [FromBody]StaffOrganizationMappingRecordRequestDto requestDto)
        {
            StaffOrganizationMappingRecordPutDto putDto = requestDto.As<StaffOrganizationMappingRecordPutDto>();
            putDto.StaffOrganizationMappingRecordId = staffOrganizationMappingRecordId;
            return this.Ok(this.staffOrganizationMappingRecordService.Update(putDto));
        }
        #endregion

        #region 删除员工组织映射记录
        /// <summary>
        ///  删除员工组织映射记录
        /// </summary>
        /// <param name="staffOrganizationMappingRecordId">员工组织映射记录Id</param>
        /// <response code="204">删除员工组织映射记录成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpDelete("{staff_organization_mapping_record_id}")]
        [Log("删除员工组织映射记录")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "staff_organization_mapping_record_id")]long staffOrganizationMappingRecordId)
        {
            this.staffOrganizationMappingRecordService.Delete(staffOrganizationMappingRecordId);
            return this.NoContent();
        }
        #endregion

        #region 获取员工组织映射记录
        /// <summary>
        ///  获取员工组织映射记录
        /// </summary>
        /// <param name="staffOrganizationMappingRecordId">员工组织映射记录Id</param>
        /// <response code="200">获取员工组织映射记录</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{staff_organization_mapping_record_id}")]
        [ProducesResponseType(typeof(StaffOrganizationMappingRecordDto), 200)]
        public IActionResult Get([FromRoute(Name = "staff_organization_mapping_record_id")]long staffOrganizationMappingRecordId)
        {
            return this.Ok(this.staffOrganizationMappingRecordService.GetEntity(staffOrganizationMappingRecordId));
        }
        #endregion

        #region 获取员工组织映射记录列表
        /// <summary>
        ///  获取员工组织映射记录列表
        /// </summary>
        /// <param name="adminId">员工Id</param>
        /// <response code="200">获取员工组织映射记录列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]/{admin_id}")]
        [ProducesResponseType(typeof(StaffOrganizationMappingRecordDto), 200)]
        public IActionResult RoleList([FromRoute(Name ="admin_id")]long adminId)
        {
            return this.Ok(this.staffOrganizationMappingRecordService.GetList(adminId));
        }
        #endregion

        #region 获取员工组织映射记录列表(公司下所有员工)
        /// <summary>
        ///  获取员工组织映射记录列表(公司下所有员工)
        /// </summary>
        /// <param name="companyId">公司Id</param>
        /// <response code="200">获取员工组织映射记录列表(公司下所有员工)</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]/{company_id}")]
        [ProducesResponseType(typeof(StaffOrganizationMappingRecordDto), 200)]
        public IActionResult CompanyStaffList([FromRoute(Name = "company_id")]int companyId)
        {
            return this.Ok(this.staffOrganizationMappingRecordService.GetCompanyStaffList(companyId));
        }
        #endregion

        #region 获取员工组织映射记录列表(部门下所有员工)
        /// <summary>
        ///  获取员工组织映射记录列表(公司下所有员工)
        /// </summary>
        /// <param name="departmentId">部门Id</param>
        /// <response code="200">获取员工组织映射记录列表(公司下所有员工)</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]/{department_id}")]
        [ProducesResponseType(typeof(StaffOrganizationMappingRecordDto), 200)]
        public IActionResult DepartmentStaffList([FromRoute(Name = "department_id")]int departmentId)
        {
            return this.Ok(this.staffOrganizationMappingRecordService.GetDepartmentStaffList(departmentId));
        }
        #endregion

        #region 获取员工组织映射记录列表(仅当前部门下所有员工，不含子级部门)
        /// <summary>
        ///  获取员工组织映射记录列表(仅当前部门下所有员工，不含子级部门)
        /// </summary>
        /// <param name="departmentId">部门Id</param>
        /// <response code="200">获取员工组织映射记录列表(公司下所有员工)</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]/{department_id}")]
        [ProducesResponseType(typeof(StaffOrganizationMappingRecordDto), 200)]
        public IActionResult CurrentlyDepartmentStaffList([FromRoute(Name = "department_id")] int departmentId)
        {
            return this.Ok(this.staffOrganizationMappingRecordService.GetCurrentlyDepartmentStaffList(departmentId));
        }
        #endregion
        
        #region 获取务部门公司员工列表
        /// <summary>
        ///  获取务部门公司员工列表
        /// </summary>
        /// <param name="companyId">公司Id</param>
        /// <param name="departmentId">部门Id</param>
        /// <response code="200">获取务部门公司员工列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]/{company_id}/{department_id}")]
        [ProducesResponseType(typeof(StaffOrganizationMappingRecordDto), 200)]
        public IActionResult NoneDepartmentStaffList([FromRoute(Name = "company_id")]int companyId, [FromRoute(Name = "department_id")]int departmentId)
        {
            return this.Ok(this.staffOrganizationMappingRecordService.GetNoneStaffList(companyId, departmentId));
        }
        #endregion

        #region 查询员工列表
        /// <summary>
        /// 查询员工列表
        /// </summary>
        /// <param name="staffName">员工姓名</param>
        /// <response code="200">数据查询成功。</response>
        /// <response code="401">用户无权限访问。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<StaffOrganizationMappingRecordDto>), 200)]
        public IActionResult SearchStaff([FromQuery(Name = "staff_name")]string staffName)
        {
            var data = this.staffOrganizationMappingRecordService.GetStaffList(staffName);
            return Ok(data);
        }
        #endregion

        #region 获取员工组织映射记录（分页）
        /// <summary>
        ///  获取员工组织映射记录（分页）
        /// </summary>
        /// <param name="companyName">公司名称</param>
        /// <param name="departmentName">部门名称</param>
        /// <param name="adminName">员工姓名</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <response code="200">获取员工组织映射记录（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<StaffOrganizationMappingRecordDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "company_name")]string companyName,
            [FromQuery(Name = "department_name")]string departmentName,
            [FromQuery(Name = "admin_name")]string adminName,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            [FromQuery(Name = "index")]int index = 1,
            [FromQuery(Name = "size")]int size = 10)
        {
            return this.Ok(this.staffOrganizationMappingRecordService.Query(companyName, departmentName,adminName, start, end, index, size));
        }
        #endregion

    }
}

